package per.turtle.common.core.web.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.NoArgsConstructor;
import per.turtle.common.core.annotation.ITree;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * TreeSelect 树结构实体类
 *
 * @author turtle
 */
@Data
@NoArgsConstructor
public class TreeSelect implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    private Object id;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect(ITree treeBean) {
        this.id = treeBean.treeId();
        this.label = treeBean.treeName();
        this.children = treeBean.treeChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

}
